/*
ID:ykzhuji1
PROG:dualpal
LANG:C++
 */
#include <iostream>
#include <fstream>
using namespace std;
char dict[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
unsigned int getNumber(unsigned int number, unsigned int base,char*buffer,unsigned int size){
	unsigned int length=0;
	unsigned int temp=number;
	while(temp){length++;temp/=base;}
	temp=number;
	if(length<=size-1){
		unsigned int i=length-1;
		while(temp){buffer[i--]=dict[(temp%base)];temp/=base;}
		buffer[length]=0;
	}
	return length;
}
bool check(unsigned int number, unsigned int base, char* buffer, unsigned int size){
	bool ret=false;
	unsigned int length=0;
	unsigned int i;
	if(length=getNumber(number,base,buffer,size)){
		for(i=0;i<=length/2;i++){
			if(buffer[i]!=buffer[length-1-i])break;
		}
		if(i>=length/2)ret=true;
	}
	return ret;
}
int main(){
	ofstream fout("dualpal.out");
	ifstream fin("dualpal.in");
#define MAX 33
	char buffer[MAX];
	unsigned int N,S,cur=0;
	fin>>N>>S;
	for(unsigned int i=S+1,cb=0;i<0xFFFFFFFF;i++,cb=0){
		for(unsigned int b=2;b<=10;b++){
			if(check(i,b,buffer,MAX))cb++;
			if(cb>=2)break;
		}
		if(cb>=2){cur++;fout<<i<<endl;}
		if(cur>=N)break;
	}
	return 0;
}
